package org.tokaf.normalizer;

import org.tokaf.TopKElement;
import org.tokaf.normalizer.ordering.Ordering;

/**
 * <p> SimpleJenaNormalizer works as SimpleNormalizer except that for Jena,
 * which in .toString method uses datatype. This feature forbids the use of
 * SimpleNormalizer with Jena.</p> <p>Copyright (c) 2006</p>
 * @author Alan Eckhardt
 * @version 1.0
 */
public class SimpleJenaNormalizer extends SimpleNormalizer {

	public SimpleJenaNormalizer(Ordering desc, String userName) {
		super(desc, userName);
	}

	public SimpleJenaNormalizer(Ordering desc) {
		super(desc);
	}

	public SimpleJenaNormalizer() {
		super();
	}

	public double Normalize(Object o) {
		if (o == null)
			return 0;
		if (o instanceof com.hp.hpl.jena.rdf.model.Literal) {
			return order.order(((com.hp.hpl.jena.rdf.model.Literal) o)
					.getDouble());
		}
		return 0;
	}

	public double Normalize(TopKElement te, int index) {
		if (te == null)
			return 0;
		return Normalize(te.getRatingObject(index));
	}

}
